var layer = require('{pub}/layer');
var template = require('template');
var request = require('request');
var tpl = renders({
    <ul class="m-list">
        <%each list%>
            <li class="list-item<%if id === $value.id%> s-crt<%/if%>" data-id="<%$value.id%>">
                <a><%$value.name%></a>
            </li>
        <%/each%>
    </ul>
})

return function(e, elem){
    var that = this;
    layer.bubble(e, template.render(tpl, {
        list:that.companyList,
        id:that.data.company.id
    }), elem, 240, 204, {
        position:{
            left:-12,
            right:null,
            top:12
        },
        onInit:function(self){
            self.element.addClass('bubble-left')
        },
        events:{
            //选择企业
            'click .list-item':function(e, elem){
                var data = elem.data();
                request.update('company/enter', {companyId:data.id}, {
                    200:function(){
                        that.renderCompany(data.id);
                    }
                }, '正在加载企业信息...')
                layer.destroy('position');
                e.stopPropagation()
            }
        }
    })
}